package edu.calpoly.android.echoes;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.MenuItem.OnMenuItemClickListener;
import android.widget.ImageView;

public class TutorialView extends Activity {
	
	private final int MAX_FRAMES = 3;
	private final int MIN_FRAMES = 0;
	private int m_currentFrame;
	
	private final int PREVIOUS = Menu.FIRST;
	private final int NEXT = Menu.FIRST + 1;
	
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.tutorial_layout1);
		
		/*Context context = getApplicationContext();
		LayoutInflater lInflate = (LayoutInflater)context.getSystemService(
				Context.LAYOUT_INFLATER_SERVICE);
		
		View imageView = lInflate.inflate(R.layout.tutorial_view, null);
		ImageView iView = (ImageView) findViewById(R.id.TutorialView);
		
		iView.setImageDrawable(new Drawable());*/
	}
	
	private void setTutorial() {
		switch(m_currentFrame) {
			case 0:
				setContentView(R.layout.tutorial_layout1);
				return;
			case 1:
				setContentView(R.layout.tutorial_layout2);
				return;
			case 2:
				setContentView(R.layout.tutorial_layout3);
				return;
			case 3:
				setContentView(R.layout.tutorial_layout4);
				return;
		}
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		
		MenuItem prev = menu.add(0, PREVIOUS, 0, "Prev");
		prev.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			public boolean onMenuItemClick(MenuItem item) {
				m_currentFrame--;
				setTutorial();
				return true;
			}
		});
		MenuItem next = menu.add(0, NEXT, 0, "Next");
		next.setOnMenuItemClickListener(new OnMenuItemClickListener() {
			public boolean onMenuItemClick(MenuItem item) {
				m_currentFrame++;
				setTutorial();
				return true;
			}
		});
		
		return true;
	}
	
	
/*	public boolean onOptionItemSelected(MenuItem item) {
		switch(item.getItemId()) {
			case PREVIOUS:
				m_currentFrame--;
				return true;
			case NEXT:
				m_currentFrame++;
				Log.e("onOptionItemSelected", m_currentFrame + "");
				return true;
			default:
				return false;
		}
	}*/
	
	public boolean onPrepareOptionsMenu(Menu menu) {
		int curr = m_currentFrame;
		
		if(curr == 0) 
			menu.findItem(PREVIOUS).setEnabled(false);
		else
			menu.findItem(PREVIOUS).setEnabled(true);
		
		if(curr == MAX_FRAMES)
			menu.findItem(NEXT).setEnabled(false);
		else
			menu.findItem(NEXT).setEnabled(true);
		
		
		return super.onPrepareOptionsMenu(menu);
	}

}
